package org.xcorpio.java8.chapter06;

import java.util.Optional;
import java.util.stream.Collectors;

import org.xcorpio.java8.common.Data;
import org.xcorpio.java8.common.Dish;

public class GeneralizedReducing {

    public static void main(String[] args) {
        Integer totalCalories = Data.Menu.stream().collect(Collectors.reducing(0, Dish::getCalories, (a, b) -> a + b));
        System.out.println("total:" + totalCalories);
        Optional<Dish> mostCalorieDish = Data.Menu.stream()
                .collect(Collectors.reducing((d1, d2) -> d1.getCalories() > d2.getCalories() ? d1 : d2));
        System.out.println("most calorie:" + mostCalorieDish);
    }
}
